package com.zhou.yygh.user.comtroller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.yygh.common.result.Result;
import com.zhou.yygh.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhou.hospital.model.user.UserInfo;
import zhou.hospital.vo.user.UserInfoQueryVo;

import java.util.Map;

import static org.apache.ibatis.ognl.DynamicSubscript.all;

@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;
    @ApiOperation("查询用户列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page,limit);
        IPage<UserInfo> pageModel =
                userInfoService.selectPage(pageParam,userInfoQueryVo);

        return Result.ok(pageModel);

    }


    @GetMapping("/lock/{userId}/{status}")
    @ApiOperation(value = "更改用户状态")
    public  Result lock(@PathVariable Long userId,
                        @PathVariable Integer status){

        userInfoService.lock(userId,status);
        return Result.ok();
    }

    @GetMapping("/show/{userId}")
    @ApiOperation(value = "用户详情")
    public  Result showUser(@PathVariable Long userId){
       Map<String,Object> map =  userInfoService.show(userId);
       return Result.ok(map);
    }

    @GetMapping("/approval/{userId}/{authStatus}")
    @ApiOperation(value = "更改审批")
    public  Result approval(@PathVariable Long userId,
                        @PathVariable Integer authStatus){

        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
